<template>
    <div>
      <el-button type="primary" size="default" @click="addList">新增</el-button>
      <el-dialog   width="80%" title="热销详情" :visible.sync="dialogTableVisible">
        <GoodsList @uptdialog="toggleDialog" :isactivity="true" :list="list" :total="total" :brandlist="brandList" @update="getVal"></GoodsList>
      </el-dialog>
      <el-dialog title="收货地址" :visible.sync="isDialogShow">
        <el-form :model="form" ref="form"  label-width="120px" :inline="false" size="mini">
          <el-form-item label="商品原价">
            {{  form.price }}
            <!-- <el-input v-model="form.price"></el-input> -->
          </el-form-item>
          <el-form-item label="商品名称">
            {{ form.name }}
            <!-- <el-input v-model="form.name"></el-input> -->
          </el-form-item>
          <el-form-item label="促销价格">
            <el-input v-model="form.promotionPrice"></el-input>
          </el-form-item>
          <el-form-item label="排序">
            <el-input v-model="form.sort"></el-input>
          </el-form-item>
          <el-form-item label="开始时间">
            <el-date-picker
              value-format="yyyy-M-d H:m:s"
              v-model="form.promotionStartTime"
              type="datetime"
              placeholder="选择日期时间">
            </el-date-picker>
            
          </el-form-item>
          <el-form-item label="结束时间">
            <el-date-picker
              value-format="yyyy-M-d H:m:s"
              v-model="form.promotionEndTime"
              type="datetime"
              placeholder="选择日期时间">
            </el-date-picker>
           
          </el-form-item>
          <el-form-item label="活动限购数量">
            <el-input v-model="form.promotionPerLimit"></el-input>
          </el-form-item>
          <el-form-item label="商品图片">
           <img style="width: 100px;height:100px" :src="form.pic" alt="">
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
        
      </el-dialog>
    </div>
</template>

<script>
import {
productsByPage,
findAllBrand
} from "@/api/goodsManage/list"
import mix from "@/mixins"
import GoodsList from "@/components/GoodsList/index.vue"
import {
  addRecommend
} from "@/api/market/list"
export default {
  mixins:[mix],
    data() {
        return {
          isDialogShow:false,
          dialogTableVisible:false,
          total:0,
          list:[],
          brandList:[],
          form:{
            "brandName": "",
            "createTime": "",
            "modifyTime": "",
            "name": "",
            "pic": "",
            "price": "",
            "productCategoryName": "",
            "productId": "",
            "productSn": "",
            "promotionEndTime": "",
            "promotionPerLimit": "",
            "promotionPrice": "",
            "promotionStartTime": "",
            "publishStatus": "",
            "recommendId": "",
            "sort": "",
            "type": ""
          }
        };
    },
      created() {
        this.init();
        findAllBrand()
        .then(res =>{
          this.brandList = res.data.items;
        })
      },
    mounted() {

    },
    methods: {
      onSubmit(){
        // 时间格式固定 2023-05-16 10:56:30
        // var year = new Date("2023-05-26T16:00:00.000Z").getFullYear();
        // var month = new Date("2023-05-26T16:00:00.000Z").getMonth();
        // var day = new Date("2023-05-26T16:00:00.000Z").getDay();
        // console.log(year+'-'+month+'-'+day)
        var obj = JSON.parse(JSON.stringify(this.form))
        obj.productId = obj.id;
        addRecommend(obj)
        .then(res =>{
          this.isDialogShow = false;
          this.dialogTableVisible = false
        })
      },
      toggleDialog(val,val1){
        console.log(val,val1)
        this.isDialogShow = val;
        var obj = JSON.parse(JSON.stringify(val1)) 
        obj.promotionPrice = ""
        obj.sort = ""
        obj.promotionPerLimit = ""
        obj.promotionStartTime = ""
        obj.promotionEndTime = ""
        this.form = obj;
      },  
      getVal(val){
        console.log(val)
        this.formData = val;
        this.init()
      },
      init(){
        productsByPage(this.start,this.limit,this.formData)
        .then(res =>{
          console.log(res)
          this.total = res.data.total;
          this.list = res.data.rows;
        })
      },
      addList(){
        this.dialogTableVisible = !this.dialogTableVisible
      }
    },  
    components:{
      GoodsList
    },
   
};
</script>

<style scoped lang="scss">

</style>
